const Router = require("@koa/router");
const homeCtrl = require("../controller/home");
const authCtrl = require("../controller/auth");
const categoriesCtrl = require("../controller/categories");
const uploadCtrl = require("../controller/upload");
const articleCtrl = require("../controller/article");
const profileCtrl = require("../controller/profile");
const blogCtrl = require("../controller/blog");

const router = new Router();

router.get("/api/test", homeCtrl.test);

// 注册登录
router.post("/api/register", authCtrl.register);
router.get("/api/captcha", authCtrl.captcha);
router.post("/api/login", authCtrl.login);

// 通用接口模块
router.get("/api/categories", categoriesCtrl.list);
router.post("/api/user/image/upload", uploadCtrl.uploadImage);

// 文章管理
router.post("/api/user/articles", articleCtrl.create); // 创建文章
router.get("/api/user/articles", articleCtrl.list); // 获取文章列表
router.get("/api/user/articles/:id", articleCtrl.detail); // 获取文章详情
router.delete("/api/user/articles/:id", articleCtrl.delete); // 删除文章
router.put("/api/user/articles/:id", articleCtrl.update); // 更新文章

// 用户信息
router.get("/api/user/profile", profileCtrl.getUserInfo); // 获取用户信息
router.put("/api/user/profile/update", profileCtrl.updateUserInfo); // 更新用户信息
router.put("/api/user/profile/password", profileCtrl.updatePassword); // 更新用户密码
router.put("/api/user/profile/avatar", profileCtrl.updateAvatar); // 获取用户头像

// 公共博客
router.get("/api/articles", blogCtrl.listArticleByCategory); // 根据分类获取文章列表
router.get("/api/articles/:id", blogCtrl.getArticleDetail); // 根据id获取文章详情

module.exports = router;
